import urllib.request
from bs4 import BeautifulSoup
import ssl
# fhand = urllib.request.urlopen('http://data.pr4e.org/romeo.txt')



# Ignore SSL certificate errors
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE

fhand = urllib.request.urlopen('http://www.baidu.com',context=ctx).read()  # 访问百度

# for line in fhand:
#     print(line.decode().strip())

soup = BeautifulSoup(fhand, 'html.parser')
print(soup)

# import urllib.request, urllib.parse, urllib.error
#
# img = urllib.request.urlopen('http://data.pr4e.org/cover3.jpg').read()
#
# fhand = open('cover3.jpg', 'wb')
# fhand.write(img)
# fhand.close()

# import urllib.request, urllib.parse, urllib.error
# import re
# import ssl
#
# # Ignore SSL certificate errors
# ctx = ssl.create_default_context()
# ctx.check_hostname = False
# ctx.verify_mode = ssl.CERT_NONE
#
# url = input('Enter - ')
# html = urllib.request.urlopen(url, context=ctx).read()
# links = re.findall(b'href="(http[s]?://.*?)"', html)
# for link in links:
#     print(link.decode())
#
# import urllib.request, urllib.parse, urllib.error
# from bs4 import BeautifulSoup
# import ssl
#
# # Ignore SSL certificate errors
# ctx = ssl.create_default_context()
# ctx.check_hostname = False
# ctx.verify_mode = ssl.CERT_NONE
#
# url = input('Enter - ')
# html = urllib.request.urlopen(url, context=ctx).read()
# soup = BeautifulSoup(html, 'html.parser')
#
# # Retrieve all of the anchor tags
# tags = soup('a')
# for tag in tags:
#     print(tag.get('href', None))